*******************************************************************************
*** Replication File 
*** MANAGEMENT PRACTICES AND CLIMATE POLICY IN CHINA



****** create cross section
use ./ManagementChina_Panel.dta, clear

xtset uniqid year

foreach vvv in   turnover capital_fa employment  elec coal oil coalOturnover oilOturnover elecOturnover {
	bysort uniqid: egen `vvv'_mean=mean(`vvv')

}
keep uniqid  mgr_tenureP mgr_tenureC lmgr_tenureC_nomiss lmgr_tenureC_miid ///
	mgr_education mgr_education_nomiss mgr_education_miid ///
	mgr_female mgr_age lmgr_age_nomiss lmgr_age_miid ///
	firmage stateown ///
	exporter exporter_nomiss exporter_miid  ///
	ccm_index z_inno_index z_process_inno z_product_inno ///
	etsfirm ets_rational ets_stringency ets_anticip zets_rational_nomiss ets_stringency_nomiss ets_anticip_nomiss ///
	zets_rational_miid ets_stringency_miid ets_anticip_miid ///
	process_inno product_inno inno_index ipc_greendum ipc_sharegreen ipc_num ipc_greennum ipc_sharegreen_nomiss ipc_greennum_nomiss ///
	lemployment_mean_nomiss lemployment_mean_miid hubei   lfirmage lfirmage2 ///
	lemployment_mean  employment_mean capital_fa_mean turnover_mean ///
	lcostgoods_mean lcostgoods_mean_nomiss lcostgoods_mean_miid ///
	elec_mean coal_mean oil_mean coalOturnover_mean oilOturnover_mean elecOturnover_mean ///
	day_week Interviewer nace1  nace2 ///
	poll_disc_nom poll_discmgt_nom poll_clim_nom emonitor_score_nom econstargets_nom econstargets_des_nom ///
	co2mont_nom co2est_nom co2est_extvalid_nom co2targets_yesno_nom co2targ_op_nom ///
	co2targ_cha_nom co2targ_tough_nom targ_not_nom targ_publ_nom targ_notfin_nom targ_bonus_nom custghg_nom custghg_voice_nom custreq_nom custgreen_nom
	

duplicates drop *, force
duplicates report uniqid 

save ./ManagementChina_CrossSection.dta, replace

********************************************************************************
* Table 1 - Summary Statistics and Sample Characteristics, by Region and for All firms
********************************************************************************

clear all
use ./ManagementChina_CrossSection.dta, clear

#delimit;
local InterviewChar "mgr_tenureC  mgr_education mgr_female mgr_age firmage stateown exporter 
	ccm_index 
	etsfirm ets_rational ets_stringency ets_anticip
	process_inno product_inno inno_index ipc_greendum ipc_sharegreen";
#delimit cr 

	bysort hubei: eststo			 : quietly estpost summarize `InterviewChar' 
					 eststo	ttest    : quietly estpost ttest     `InterviewChar' , by(hubei)
					 eststo All_Firms: quietly estpost summarize `InterviewChar'
	esttab using Table1_Part1.csv, b(%9.2f) cells("mean" "sd" "count" "p") nonote label nodepvar replace 
estimates clear	

* Orbis and energy
clear all
use ./ManagementChina_Panel.dta, clear

#delimit;
local OrbisEnergy "turnover employment capital_fa  costgoods 
 oil coal elec  oilOturnover coalOturnover   elecOturnover";
#delimit cr 

	bysort hubei: eststo			 : quietly estpost summarize `OrbisEnergy' 
					 eststo	ttest    : quietly estpost ttest     `OrbisEnergy' , by(hubei)
					 eststo All_Firms: quietly estpost summarize `OrbisEnergy'
	esttab using Table1_Part2.csv, b(%9.2f) cells("mean" "sd" "count" "p") nonote label nodepvar replace 

estimates clear	

********************************************************************************
* Figure 1 - Distribution of the Climate Change Management Index
********************************************************************************
use ./ManagementChina_CrossSection.dta, clear	
histogram ccm_index, xlabel(-2(1)2) xtitle(Normalized CCM Index) ///
	kdensity graphregion(color(white)) bin(14) scheme(s2mono)
graph export Figure1.jpg, replace


********************************************************************************
*Table 2: Climate Change Management and Productivity
********************************************************************************
clear all
use ./ManagementChina_Panel.dta, clear

# delimit ; 
local Controls "lmgr_tenureC_nomiss lmgr_tenureC_miid 
				 mgr_education_miid mgr_education_nomiss  
				 mgr_female 
				  lmgr_age_nomiss  lmgr_age_miid 
				 i.day_week i.Interviewer i.year i.nace2";
local Controls2 "exporter_nomiss exporter_miid 
				 hubei stateown lfirmage lfirmage2 
				 lemployment_nomiss lemployment_miid";
# delimit cr 			

eststo: xi: reg lturnover ccm_index `Controls', vce(cluster uniqid) 
eststo: xi: reg lturnover ccm_index `Controls' `Controls2', vce(cluster uniqid)
eststo: xi: reg lturnover ccm_index `Controls' `Controls2' ///
					lcapital_fa_nomiss lcapital_fa_miid ///
					lcostgoods_nomiss lcostgoods_miid , vce(cluster uniqid)
 
  esttab using Table2.csv, replace scalars(N_clust r2 r2_a) se starlevels(* .10 ** .05 *** .01) b(3) drop(exporter_nomiss exporter_miid lemployment_miid lcapital_fa_miid lfirmage lfirmage2 lcostgoods_miid lmgr_tenureC_nomiss lmgr_tenureC_miid mgr_education_miid mgr_education_nomiss mgr_female  lmgr_age_nomiss  lmgr_age_miid _Iday_week* _IIntervi* _Inace2* _Iyear*) ///
nonote label title( "Table: Firm Performance and CCM Index" ) 
estimates clear
	
	
********************************************************************************
* Table 3: Green Patents and Innovation Practices
********************************************************************************
clear all
use ./ManagementChina_CrossSection.dta, clear	

* Dummy if the firm reported any patent
gen Innovate = ipc_num>0 & ipc_num<.
gen InnovateGreen = ipc_greennum>0 & ipc_greennum<.

* Dummy if the firm reported any green patent 
gen tag_greennum  = ipc_greennum == .

* Share of green innovation 
gen ipc_shareGreenInnovOnlyIfInno=ipc_sharegreen_nomiss if ipc_num>0 & ipc_num<.

label var Innovate "Any patent"
label var InnovateGreen "Any green patent"
label var ipc_greennum "Green patent"
label var ipc_shareGreenInnovOnlyIfInno "Green patent share"

# delimit;
local Controls "exporter_nomiss exporter_miid hubei stateown  lfirmage 
				lemployment_mean_nomiss lemployment_mean_miid 
				lmgr_tenureC_nomiss lmgr_tenureC_miid 
				mgr_education_miid mgr_education_nomiss mgr_female 
				 lmgr_age_nomiss  lmgr_age_miid lcostgoods_mean_nomiss lcostgoods_mean_miid";
local Controls2 "i.day_week i.Interviewer i.nace1";
# delimit cr 


foreach x in ccm_index z_inno_index z_process_inno z_product_inno {
	
	if "`x'" == "ccm_index" 	local name CCMI
	if "`x'" == "z_inno_index" 		local name Inno
	if "`x'" == "z_process_inno" 	local name Proc
	if "`x'" == "z_product_inno" 	local name Prod
	
	
	disp in r "Varx: `x', regression Innovate"
eststo : xi: reg Innovate 		`x' `Controls' `Controls2', robust			
eststo : xi: reg InnovateGreen 	`x' `Controls' `Controls2', robust			
eststo : xi: reg InnovateGreen 	`x' `Controls' `Controls2' if ipc_num!=0 & ipc_num<., robust		
eststo : xi: nbreg ipc_greennum `x' `Controls' `Controls2' if ipc_num!=0, vce(robust)
		
eststo : xi: reg ipc_shareGreenInnovOnlyIfInno 	`x' `Controls'  `Controls2', robust		

}

esttab using Table3.csv, replace scalars(r2 r2_a cmd) se starlevels(* .10 ** .05 *** .01) b(3) ///
drop(exporter_nomiss exporter_miid hubei stateown  lfirmage lemployment_mean_nomiss lemployment_mean_miid lmgr_tenureC_nomiss ///
 lmgr_tenureC_miid mgr_education_miid mgr_education_nomiss mgr_female  lmgr_age_nomiss  lmgr_age_miid lcostgoods_mean_nomiss lcostgoods_mean_miid _Iday_week_* _IInterview_* _Inace1_* lnalpha) ///
nonote label title( "Table : Green Patents and Green Innovation Practices" )
estimates clear

	
********************************************************************************
* Table 4: ETS Impact on Energy Use
********************************************************************************
clear all
use ./ManagementChina_Panel.dta, clear
collapse (mean) ccm_index  coal  oil elec coalOturnover oilOturnover elecOturnover, by(uniqid nace1 nace2 etsfirm pre2013)
reshape wide coalOturnover oilOturnover elecOturnover elec  coal  oil, i(uniqid etsfirm nace1 nace2) j(pre2013) 

* Midpoint growth rate of fuel use and fuel intensity
foreach fff in coal oil elec coalOturnover oilOturnover elecOturnover  {
	gen `fff'_arcgr=(`fff'0-`fff'1)/(0.5*(`fff'0+`fff'1))
	}

* above-median CCM index
summ ccm_index , d
gen bestmanage=1 if ccm_index>r(p50)
replace bestmanage=0 if bestmanage==.
gen etsXbestmanage=etsfirm*bestmanage
label var bestmanage "Above-median CCM index"
label var etsXbestmanage "X ETS firm"
label var etsfirm "ETS firm"

foreach fff in coal  oil elec  {
eststo: xi:	reg `fff'_arcgr etsfirm, robust 
eststo: xi:	reg `fff'_arcgr etsfirm bestmanage etsXbestmanage, robust 
	}

	foreach fff in coalOturnover oilOturnover elecOturnover {
eststo: xi:	reg `fff'_arcgr etsfirm, robust 
eststo: xi:	reg `fff'_arcgr etsfirm bestmanage etsXbestmanage, robust 
	}
	
esttab using Table4.csv , replace scalars(r2 r2_a cmd) se starlevels(* .10 ** .05 *** .01) b(3) ///
title( "Table: ETS Impact on Energy Use/Intensity" ) nonote label nodepvar  
estimates clear


********************************************************************************
* Table 5: ETS Impact on Growth of Energy Use and Intensity with Controls
********************************************************************************
clear all
use ./ManagementChina_Panel.dta, clear
collapse (mean) ccm_index  coal  oil elec coalOturnover oilOturnover elecOturnover employment labor_intensity turnover capital_fa firmage , by(uniqid etsfirm stateown pre2013  )

reshape wide elec coal  oil coalOturnover oilOturnover elecOturnover employment labor_intensity turnover capital_fa, i(uniqid etsfirm stateown firmage ccm_index) j(pre2013) 

foreach fff in coal oil elec coalOturnover oilOturnover elecOturnover {
	gen `fff'_arcgr=(`fff'0-`fff'1)/(0.5*(`fff'0+`fff'1))
	}

summ ccm_index, d
gen bestmanage=1 if ccm_index>r(p50)
replace bestmanage=0 if bestmanage==.
gen etsXbestmanage=etsfirm*bestmanage

summ firmage, d
gen firmage_aboveM=1 if firmage>r(p50)
replace firmage_aboveM=0 if firmage_aboveM==.
gen etsXfirmage_aboveM=etsfirm*firmage_aboveM
gen etsXSOE=etsfirm*stateown

keep if elec_arcgr!=. |  coal_arcgr!=. | oil_arcgr!=. 

foreach fff in coal oil elec coalOturnover oilOturnover elecOturnover{
	summ `fff'1 if `fff'_arcgr!=., d
	gen `fff'_aboveMed=1 if `fff'1>r(p50) & `fff'_arcgr!=.
	replace `fff'_aboveMed=0 if `fff'_aboveMed==. & `fff'_arcgr!=.
	gen etsX`fff'_aboveMed=etsfirm*`fff'_aboveMed
	}
	
foreach fff in employment labor_intensity turnover capital_fa {
	summ `fff'1, d
	gen `fff'_aboveMed=1 if `fff'1>r(p50) 
	replace `fff'_aboveMed=0 if `fff'_aboveMed==. 
	gen etsX`fff'_aboveMed=etsfirm*`fff'_aboveMed
	}

estimates clear 
local ii=1
foreach fff in coal oil elec coalOturnover oilOturnover elecOturnover  {
	preserve
	rename `fff'_aboveMed fuel_aboveMed
	rename etsX`fff'_aboveMed etsXfuel_aboveMed
	reg `fff'_arcgr etsfirm bestmanage etsXbestmanage fuel_aboveMed etsXfuel_aboveMed  stateown etsXSOE employment_aboveMed etsXemployment_aboveMed labor_intensity_aboveMed etsXlabor_intensity_aboveMed turnover_aboveMed etsXturnover_aboveMed capital_fa_aboveMed etsXcapital_fa_aboveMed firmage_aboveM etsXfirmage_aboveM, robust 
	restore
	estimates store r`ii++'
	}

esttab r* using Table5.csv, replace scalars(r2 r2_a cmd) se starlevels(* .10 ** .05 *** .01) b(3) ///
title( "Table : ETS Impact on Growth of Energy Use with Management and Size" )

*creating lists of firms with data availability for appendix.
preserve
reg elec_arcgr etsfirm bestmanage etsXbestmanage, robust
keep if e(sample)==1
keep uniqid
save ./listfirmswithElec.dta,replace
restore
preserve 
reg coal_arcgr etsfirm bestmanage etsXbestmanage, robust
keep if e(sample)==1
keep uniqid
save ./listfirmswithCoal.dta,replace
restore
preserve
reg oil_arcgr etsfirm bestmanage etsXbestmanage, robust
keep if e(sample)==1
keep uniqid
save ./listfirmswithOil.dta,replace
restore

********************************************************************************
* Table 6: ETS Impact - Poisson Specification (2008-2014)
********************************************************************************

clear all
use ./ManagementChina_Panel.dta, clear
gen After2012=0 
replace After2012=1 if year>2012
gen ETSXAfter2012=After2012*etsfirm

summ ccm_index if etsfirm==1, d
gen bestmanage=1 if ccm_index>r(p50)
replace bestmanage=0 if bestmanage==.
gen etsXbestmanageXAfter2012=etsfirm*bestmanage*After2012

label var etsXbestmanageXAfter2012 "X Above-median CCM index"
label var ETSXAfter2012 "ETS firm X Post 2012"

xtset uniqid year

foreach fff in coal oil elec    {
eststo: xi:	xtpoisson `fff' ETSXAfter2012 etsXbestmanageXAfter2012 i.year ,fe vce(robust)
	}

esttab using Table6.csv , replace scalars( N_g cmd) se starlevels(* .10 ** .05 *** .01) b(3) ///
drop(_Iyear_*  ) title( "Table : ETS Impact - Poisson Specification (2008-2014)" )  nonote label nodepvar  
estimates clear


********************************************************************************
* Figure 2: Trends in Energy Consumption (2008-2014)
********************************************************************************
clear all
use ./ManagementChina_Panel.dta, clear
summ ccm_index if etsfirm==1, d
gen bestmanage=1 if ccm_index>r(p50)
replace bestmanage=0 if bestmanage==.

forvalues yyy=2007/2015 {
	gen Dum`yyy' =0
	replace Dum`yyy'=1 if year==`yyy'
	gen ETSX`yyy'=Dum`yyy'*etsfirm
	gen etsXbestmanageX`yyy'=etsfirm*bestmanage*Dum`yyy'
	}
	gen notbestmanage=0
	replace notbestmanage=1 if bestmanage!=1
	forvalues yyy=2007/2015 {
	gen etsXnotbestmanageX`yyy'=etsfirm*notbestmanage*Dum`yyy'
	}

foreach fff in coal  oil elec {
	preserve
		xtpoisson `fff'  etsXnotbestmanageX2008 ///
		etsXnotbestmanageX2009 etsXnotbestmanageX2011 etsXnotbestmanageX2012 ///
		etsXnotbestmanageX2013 etsXnotbestmanageX2014   ///
		 etsXbestmanageX2008 etsXbestmanageX2009   ///
		etsXbestmanageX2011 etsXbestmanageX2012 etsXbestmanageX2013 etsXbestmanageX2014 ///
		  Dum2008 Dum2009   Dum2011 Dum2012 Dum2013 Dum2014 ///
		 ,fe vce(robust)

** Store coefficients as variables       
regsave, ci
drop  N

gen 	bestmanage=. 
replace bestmanage= 1 if strmatch(var, "*etsXbestm*")==1
replace bestmanage= 0 if strmatch(var, "*etsXnotbestm*")==1
gen year=substr(var,-4,.)
drop if bestmanage==.
drop var
reshape wide coef ci_lower ci_upper  stderr , i(year) j(bestmanage) 
 insobs 1, before(3)
replace year = "2010" in 3
replace coef0 = 0 in 3
replace stderr0 = 0 in 3
replace ci_lower0 = 0 in 3
replace ci_upper0 = 0 in 3
replace coef1 = 0 in 3
replace stderr1 = 0 in 3
replace ci_lower1 = 0 in 3
replace ci_upper1 = 0 in 3
destring year, replace
gen y=0


			twoway ///
            (rarea  ci_lower0 ci_upper0  year, col(black%30) fint(inten30) lwidth(0.1)) ///
            (rarea  ci_lower1 ci_upper1  year, col(black%80) fint(inten30) lwidth(0.05)) ///
            (line coef1 year , lcol(black) lwidth(medthick))  /// 
            (scatter coef1 year , col(black) msize(1)) ///
			(line coef0 year , lcol(black) lwidth(medthick) lpattern(dash))  /// 
            (scatter coef0 year , col(black) msize(1)) ///
			(line y year , lpattern(dot) lcolor(gray) lwidth(0.5)) , ///
            graphregion(fcolor(white)) legend(off) graphregion(lcolor(255 255 255))  /// 
            xline(2010.5, lpattern(dot) lcolor(black) lwidth(0.4)) xline(2012.5, lpattern(dot) lcolor(black) lwidth(0.4)) ///
			xlab(2008(1)2014) ylab(-3(1)3, labsize(medium) gstyle(dot) glwidth(0.15) )
			graph export "Fig3_xtpoisson_`fff'.png", as(png) replace
			
			twoway ///
            (rarea  ci_lower0 ci_upper0  year, col(black%30) fint(inten30) lwidth(0.1)) ///
            (rarea  ci_lower1 ci_upper1  year, col(black%80) fint(inten30) lwidth(0.05)) ///
            (line coef1 year , lcol(black) lwidth(medthick))  /// 
            (scatter coef1 year , col(black) msize(1)) ///
			(line coef0 year , lcol(black) lwidth(medthick) lpattern(dash))  /// 
            (scatter coef0 year , col(black) msize(1)) ///
			(line y year , lpattern(dot) lcolor(gray) lwidth(0.5)) , ///
			legend (order(4 2 6 1) label(4 "") label(2 "Above Median CCMI")  label(6 "") label(1 "Below Median CCMI") ///
				label(3 "") label(5 "") label(7 "") pos(6) col(2)) ///
            graphregion(fcolor(white))  graphregion(lcolor(255 255 255))  /// 
            xline(2010.5, lpattern(dot) lcolor(black) lwidth(0.4)) xline(2012.5, lpattern(dot) lcolor(black) lwidth(0.4)) ///
			xlab(2008(1)2014) ylab(-3(1)3, labsize(medium) gstyle(dot) glwidth(0.15) )
			graph export "Fig3_xtpoisson_`fff'_withlegend.png", as(png) replace
restore
}



********************************************************************************
* Table 7: Climate Change Management and Trading Behavior
********************************************************************************

use ./ManagementChina_CrossSection, clear
# delimit ; 
local Controls "exporter_nomiss exporter_miid hubei stateown lfirmage lfirmage2 
				lemployment_mean_nomiss lemployment_mean_miid
				lmgr_tenureC_nomiss lmgr_tenureC_miid mgr_education_miid mgr_education_nomiss 
				mgr_female  lmgr_age_nomiss  lmgr_age_miid i.day_week i.Interviewer i.nace2";
# delimit cr 	

label var etsfirm "ETS participation"
label var zets_rational_nomiss "Rationality of current trading"
label var ets_stringency_nomiss "Stringency of current ETS"
label var ets_anticip_nomiss "Anticipated stringency of future ETS"

eststo: xi: reg ccm_index  etsfirm `Controls', robust
eststo: xi:  reg  ccm_index  zets_rational_nomiss zets_rational_miid `Controls' if etsfirm==1, robust
eststo: xi:  reg  ccm_index  ets_stringency_nomiss ets_stringency_miid `Controls' if etsfirm==1, robust
eststo: xi:  reg  ccm_index  ets_anticip_nomiss ets_anticip_miid `Controls', robust

esttab using Table7.csv, replace scalars(r2 r2_a cmd) se starlevels(* .10 ** .05 *** .01) b(3) ///
drop(lfirmage lfirmage2 lmgr_tenureC_nomiss lmgr_tenureC_miid mgr_education_miid mgr_education_nomiss mgr_female  lmgr_age_nomiss exporter_nomiss hubei stateown lemployment_mean_nomiss zets_rational_miid ets_stringency_miid ets_anticip_miid exporter_miid lemployment_mean_miid  lmgr_age_miid _Inace2* _Iday_week* _IIntervi*) ///
title(  "Table 7: Climate Change Management and Trading Behaviour" ) nonote label nodepvar 
estimates clear



********************************************************************************
* Table 8: ETS Impact on Growth of Coal Use by CCMI Components
********************************************************************************

clear all
use ./ManagementChina_Panel.dta, clear
collapse (mean) ccm_index zaware_pos_CCM zemonitor_CCM zeconstargets_score_CCM zco2monitor_score_CCM zco2targets_score_CCM zenforce_score_CCM zcustpress_score_CCM coalOturnover oilOturnover elecOturnover elec  coal  oil, by(uniqid nace1 nace2 etsfirm pre2013)
reshape wide coalOturnover oilOturnover elecOturnover elec  coal  oil, i(uniqid etsfirm ) j(pre2013) 

foreach fff in coalOturnover oilOturnover elecOturnover coal oil elec {
	gen `fff'_arcgr=(`fff'0-`fff'1)/(0.5*(`fff'0+`fff'1))
	}

foreach fff in mean  {
summ ccm_index , d
gen bestmanage=1 if ccm_index>r(`fff')
replace bestmanage=0 if bestmanage==.
gen etsXbestmanage=etsfirm*bestmanage

summ zaware_pos_CCM, d
gen aboveM_awareness=1 if zaware_pos_CCM>r(`fff')
replace aboveM_awareness=0 if aboveM_awareness==.
gen etsXaboveM_awareness=etsfirm*aboveM_awareness

summ zemonitor_CCM, d
gen aboveM_Emonitor=1 if zemonitor_CCM>r(`fff')
replace aboveM_Emonitor=0 if aboveM_Emonitor==.
gen etsXaboveM_Emonitor=etsfirm*aboveM_Emonitor

summ zeconstargets_score_CCM, d
gen aboveM_Etarget=1 if zeconstargets_score_CCM>r(`fff')
replace aboveM_Etarget=0 if aboveM_Etarget==.
gen etsXaboveM_Etarget=etsfirm*aboveM_Etarget

summ zco2monitor_score_CCM, d
gen aboveM_co2monitor=1 if zco2monitor_score_CCM>r(`fff')
replace aboveM_co2monitor=0 if aboveM_co2monitor==.
gen etsXaboveM_co2monitor=etsfirm*aboveM_co2monitor

summ zco2targets_score_CCM, d
gen aboveM_co2target=1 if zco2targets_score_CCM>r(`fff')
replace aboveM_co2target=0 if aboveM_co2target==.
gen etsXaboveM_co2target=etsfirm*aboveM_co2target

summ zenforce_score_CCM, d
gen aboveM_enforce=1 if zenforce_score_CCM>r(`fff')
replace aboveM_enforce=0 if aboveM_enforce==.
gen etsXaboveM_enforce=etsfirm*aboveM_enforce

summ zcustpress_score_CCM, d
gen aboveM_custpress=1 if zcustpress_score_CCM>r(`fff')
replace aboveM_custpress=0 if aboveM_custpress==.
gen etsXaboveM_custpress=etsfirm*aboveM_custpress
}

global a "aboveM_awareness etsXaboveM_awareness"
global b "aboveM_Emonitor etsXaboveM_Emonitor"
global c "aboveM_Etarget etsXaboveM_Etarget"
global d "aboveM_co2monitor etsXaboveM_co2monitor"
global e "aboveM_co2target etsXaboveM_co2target"
global f "aboveM_enforce etsXaboveM_enforce"
global g "aboveM_custpress etsXaboveM_custpress"

foreach vvv in "$a" "$b" "$c" "$d" "$e" "$f" "$g"  {
eststo: xi: reg coal_arcgr etsfirm `vvv', robust
	}
	
esttab using Table8.csv , replace scalars(r2 r2_a cmd) se starlevels(* .10 ** .05 *** .01) b(3) ///
title( "Table : ETS Impact on Growth of Coal Use by CCMI Components" ) nonote label nodepvar 
estimates clear



********************************************************************************
* Figure 3: Counterfactual Reduction in Coal Consumption
********************************************************************************
clear all
use ./ManagementChina_Panel.dta, clear
gen After2012=0 
replace After2012=1 if year>2012
gen ETSXAfter2012=After2012*etsfirm

	
summ ccm_index if etsfirm==1, d
gen bestmanage=1 if ccm_index>r(p50)
replace bestmanage=0 if bestmanage==.
gen etsXbestmanageXAfter2012=etsfirm*bestmanage*After2012

xtset uniqid year

collapse (mean) ccm_index elec coal  oil, by(uniqid etsfirm After2012 bestmanage)
reshape wide elec  coal  oil, i(uniqid etsfirm ccm_index bestmanage) j(After2012) 
foreach fff in elec coal oil  {
	gen `fff'_arcgr=(`fff'1-`fff'0)/(0.5*(`fff'1+`fff'0))
	}

rename coal1 coal_postETS
rename coal0 coal_preETS

gen etsXbestmanage=etsfirm*bestmanage
* only keep firms with positive coal before and after
drop if coal_preETS==. | coal_postETS==.
drop if coal_preETS==0 | coal_postETS==0

*counterfactual of badly managed becoming well managed 
gen coal_arcgr_CFBadtoGood=coal_arcgr-(1.499-0.375) if bestmanage==0 & etsfirm==1
replace coal_arcgr_CFBadtoGood=2 if coal_arcgr_CFBadtoGood>2 & coal_arcgr_CFBadtoGood!=. 
replace coal_arcgr_CFBadtoGood=-2 if coal_arcgr_CFBadtoGood<-2 & coal_arcgr_CFBadtoGood!=. 
gen coal_postCFBadtoGood= coal_postETS    
replace coal_postCFBadtoGood= coal_preETS * (1+ coal_arcgr_CFBadtoGood*0.5)  / ///
					(1 - (coal_arcgr_CFBadtoGood)*0.5) if bestmanage==0 & etsfirm==1
replace coal_postCFBadtoGood = 0 if coal_postETS == 0 & bestmanage==0 & etsfirm==1

		
*** calculating aggregates
gen N=1
keep if etsfirm==1
collapse (sum) N coal_postETS coal_preETS coal_postCFBadtoGood 

save  "./Forcounterfactual.dta", replace

*This data is then used in code Figure3_Rcode.Rmd to generate Figure 3

********************************************************************************
* Table A.1: Sample Selection
********************************************************************************

use  "./SampleSelection.dta", clear
estimates clear
xtset firmid year
local ii=1
foreach vvv in turnover capital   {
	replace `vvv'=`vvv'/1000000
	}
	replace employment =employment/10
foreach vvv in turnover capital employment{
	reg `vvv' Interview_Contacted ETS  i.NACE_3dig i.year, cluster(firmid)
	estimates store r`ii++'
	}

foreach vvv in turnover capital employment{
	reg `vvv' Interview_Success ETS  i.NACE_3dig i.year if Interview_Contacted==1, cluster(firmid)
	estimates store r`ii++'
}
esttab r* using TableA1.csv , replace scalars(r2 r2_a cmd N_clust) se starlevels(* .10 ** .05 *** .01) b(3) drop (  1* 2* 3* 4* 5* 6* 7* 8* 9*)

********************************************************************************
* Table A.2: Survey Response Rates by ETS Location
********************************************************************************
use  "./SampleSelection.dta", clear
keep  firmid employment  Beijing ETS    Interview_Contacted Interview_Success year
reshape wide employment, i(firmid  Beijing ETS    Interview_Contacted Interview_Success) j(year)
drop empl*
gen n=1
collapse (sum)n, by (Beijing ETS    Interview_Contacted Interview_Success)
reshape wide n, i( ETS    Interview_Contacted Interview_Success) j(Beijing)
rename n0 HubeiFirms
rename n1 BeijingFirms
drop if Interview_Contacted==0
export delimited using TableA2.csv, replace
*Then paste TableA2.csv in TableA2.xls to obtain Table A2 as formatted in paper

********************************************************************************
*** Figure A.1 - Double Scoring ***
********************************************************************************
clear all
use ./ManagementChina_Panel.dta, clear

keep doublescore_* ccm_index uniqid

duplicates drop 

gen double_score=0
replace double_score=1 if doublescore_sxc==1| doublescore_gzl==1| doublescore_cyc==1| doublescore_zj ==1|doublescore_cj==1| doublescore_hy ==1|doublescore_ljq==1| doublescore_wxy==1| doublescore_pzw==1

kdensity ccm_index if double_score==0, lc(grey) lwidth(medthick) plot(kdensity ccm_index if double_score==1, lc(black) lwidth(medthick)  lpattern(dash)) /// 
legend(order(1 "Not Double Scored" 2 "Double Scored")  rows(1)) xtitle("Score") graphregion(color(white)) title("") note("")
	  graph export FigureA1.pdf, replace

********************************************************************************
* Figure A.2: Distribution of Climate Change Management Index: Components
********************************************************************************
clear all
use ./ManagementChina_Panel.dta, clear
collapse (mean) ccm_index zaware_pos_CCM zemonitor_CCM zeconstargets_score_CCM zco2monitor_score_CCM zco2targets_score_CCM zenforce_score_CCM zcustpress_score_CCM coalOturnover oilOturnover elecOturnover elec  coal  oil, by(uniqid  etsfirm pre2013)
reshape wide coalOturnover oilOturnover elecOturnover elec  coal  oil, i(uniqid etsfirm ) j(pre2013) 

label var zaware_pos_CCM "Awareness"
label var zemonitor_CCM "Energy monitoring" 
label var zeconstargets_score_CCM "Energy target"  
label var zco2monitor_score_CCM "GHG monitoring"
label var zco2targets_score_CCM "GHG target"
label var zenforce_score_CCM "Target enforcement"
label var zcustpress_score_CCM "Customer pressure"

foreach vvv in zaware_pos_CCM zemonitor_CCM zeconstargets_score_CCM zco2monitor_score_CCM /// 
			 zco2targets_score_CCM zenforce_score_CCM zcustpress_score_CCM {
			 
			 hist `vvv', scheme(s1color) name(`vvv', replace ) xscale(range(0 3))
			 
			 }
			graph combine   zaware_pos_CCM zemonitor_CCM zeconstargets_score_CCM zco2monitor_score_CCM zco2targets_score_CCM zenforce_score_CCM zcustpress_score_CCM, scheme(s1color)
graph export "./FigureA2.jpg", as(jpg) replace 
	
	
********************************************************************************
*Table A.3: Raw correlations of Climate Change Management Index with firm characteristics
********************************************************************************

clear all
use ./ManagementChina_Panel.dta, clear
collapse (mean) ccm_index employment labor_intensity capital_fa turnover coal oil elec firmage mgr_tenureC, by(stateown beijing uniqid etsfirm pre2013)
keep if pre2013==1
global f_var employment labor_intensity capital_fa turnover coal oil elec firmage mgr_tenureC stateown etsfirm beijing 

asdoc pwcorr ccm_index $f_var , sig  star(all) replace save(TableA3.doc)

estimates clear


********************************************************************************
*Table A.4: Climate Change Management Index Components
********************************************************************************
clear all
use ./ManagementChina_CrossSection.dta, clear
estimates clear
eststo: estpost summarize  poll_disc_nom poll_discmgt_nom poll_clim_nom emonitor_score_nom econstargets_nom econstargets_des_nom ///
co2mont_nom co2est_nom co2est_extvalid_nom co2targets_yesno_nom co2targ_op_nom ///
 co2targ_cha_nom co2targ_tough_nom targ_not_nom targ_publ_nom targ_notfin_nom targ_bonus_nom custghg_nom custghg_voice_nom custreq_nom custgreen_nom, listwise
esttab using  ./TableA4.csv , cells("mean sd") label nodepvar replace

********************************************************************************
*Table A.5: Summary Statistics and Sample Characteristics by ETS status
********************************************************************************
clear all
use ./ManagementChina_CrossSection.dta, clear

#delimit;
local InterviewChar "mgr_tenureC mgr_tenureP mgr_education mgr_female mgr_age firmage stateown exporter 
	ccm_index ets_stringency ets_anticip
	 process_inno product_inno inno_index ipc_greendum ipc_sharegreen ";
#delimit cr 

	bysort etsfirm:  eststo			 : quietly estpost summarize `InterviewChar' 
					 eststo	ttest    : quietly estpost ttest     `InterviewChar' , by(etsfirm)
esttab using TableA5_1.csv, b(%9.2f) cells("mean" "sd" "count" "p") nonote label nodepvar replace 
estimates clear

	bysort etsfirm:  eststo			 : quietly estpost summarize `InterviewChar' if hubei==0
					 eststo	ttest    : quietly estpost ttest     `InterviewChar' if hubei==0 , by(etsfirm)
esttab using TableA5_BJ.csv, b(%9.2f) cells("mean" "sd" "count" "p") nonote label nodepvar replace 
estimates clear

	bysort etsfirm:  eststo			 : quietly estpost summarize `InterviewChar' if hubei==1
					 eststo	ttest    : quietly estpost ttest     `InterviewChar' if hubei==1 , by(etsfirm)
esttab using TableA5_HB.csv, b(%9.2f) cells("mean" "sd" "count" "p") nonote label nodepvar replace 
estimates clear

* Carbon market indices
eststo	: quietly estpost summarize ets_rational 
eststo	: quietly estpost summarize ets_rational if hubei==0
eststo	: quietly estpost summarize ets_rational if hubei==1
esttab using TableA5_etsRational.csv, b(%9.2f) cells("mean" "sd" "count" "p") nonote label nodepvar replace 
estimates clear

* Orbis and energy
clear all
use ./ManagementChina_Panel.dta, clear
#delimit;
local OrbisEnergy "turnover employment capital_fa  costgoods 
 oil coal elec  oilOturnover coalOturnover   elecOturnover";
#delimit cr 

bysort etsfirm: eststo			 : quietly estpost summarize `OrbisEnergy' 
				eststo	ttest    : quietly estpost ttest     `OrbisEnergy' , by(etsfirm)
	esttab using TableA5_OrbisEnergy.csv, b(%9.2f) cells("mean" "sd" "count" "p") nonote label nodepvar replace 
estimates clear

bysort etsfirm: eststo			 : quietly estpost summarize `OrbisEnergy' if hubei==0
				eststo	ttest    : quietly estpost ttest     `OrbisEnergy' if hubei==0, by(etsfirm)
	esttab using TableA5BJ_OrbisEnergy.csv, b(%9.2f) cells("mean" "sd" "count" "p") nonote label nodepvar replace 
estimates clear	

bysort etsfirm: eststo			 : quietly estpost summarize `OrbisEnergy' if hubei==1
				eststo	ttest    : quietly estpost ttest     `OrbisEnergy' if hubei==1, by(etsfirm)
	esttab using TableA5HB_OrbisEnergy.csv, b(%9.2f) cells("mean" "sd" "count" "p") nonote label nodepvar replace 
estimates clear	

********************************************************************************
*Table A.6: Non-Zero Observations by Year
********************************************************************************
clear all
use ./ManagementChina_Panel.dta, clear
foreach fff in coal oil elec    {
gen count`fff'=1 if `fff'!=. &`fff'>0
	}
collapse (sum) countcoal countoil countelec  , by (year)
export excel using "./TableA6.csv", firstrow(variables) replace

	
********************************************************************************
*Table A.7: Energy Data Availability
********************************************************************************
use ./ManagementChina_Panel.dta, clear

foreach fff in coal oil elec {
	gen `fff'year=0
	replace `fff'year=1 if `fff' !=.
	}
foreach fff in coal oil elec {
	gen `fff'nonZeroY=0
	replace `fff'nonZeroY=1 if `fff' !=. & `fff' !=0
	}
collapse (sum) coalyear oilyear elecyear coalnonZeroY oilnonZeroY elecnonZeroY (mean) employment  capital_fa turnover costgoods , by(firmage stateown etsfirm hubei uniqid   day_week Interviewer ccm_index nace2 )
mmerge uniqid using ./listfirmswithCoal	
gen withcoal=0
replace withcoal=1 if _m==3

drop _m
mmerge uniqid using ./listfirmswithElec
gen withelec=0
replace withelec=1 if _m==3	

mmerge uniqid using ./listfirmswithOil	
gen withoil=0
replace withoil=1 if _m==3

foreach fff in  employment  capital_fa turnover costgoods firmage {
	summ `fff', d
	gen `fff'_aboveMed=1 if `fff'>r(p50)
	replace `fff'_aboveMed=0 if `fff'_aboveMed==. 
	gen etsX`fff'_aboveMed=etsfirm*`fff'_aboveMed
	}
summ ccm_index , d
gen bestmanage=1 if ccm_index>r(p50)
replace bestmanage=0 if bestmanage==.
	
estimates clear 
reg coalyear etsfirm hubei employment_aboveMed capital_fa_aboveMed turnover_aboveMed stateown  firmage_aboveMed bestmanage  i.day_week i.Interviewer  i.nace2, robust
estimates store r1
reg oilyear etsfirm hubei employment_aboveMed capital_fa_aboveMed turnover_aboveMed stateown  firmage_aboveMed bestmanage  i.day_week i.Interviewer  i.nace2, robust
estimates store r2
reg elecyear etsfirm hubei employment_aboveMed capital_fa_aboveMed turnover_aboveMed stateown  firmage_aboveMed bestmanage  i.day_week i.Interviewer  i.nace2, robust
estimates store r3
reg coalnonZeroY etsfirm hubei employment_aboveMed capital_fa_aboveMed turnover_aboveMed stateown  firmage_aboveMed bestmanage  i.day_week i.Interviewer  i.nace2 , robust
estimates store r4
reg oilnonZeroY etsfirm hubei employment_aboveMed capital_fa_aboveMed turnover_aboveMed stateown  firmage_aboveMed bestmanage  i.day_week i.Interviewer  i.nace2 , robust
estimates store r5
reg elecnonZeroY etsfirm hubei employment_aboveMed capital_fa_aboveMed turnover_aboveMed stateown  firmage_aboveMed bestmanage  i.day_week i.Interviewer  i.nace2 , robust
estimates store r6
reg withcoal etsfirm hubei employment_aboveMed capital_fa_aboveMed turnover_aboveMed stateown  firmage_aboveMed bestmanage  i.day_week i.Interviewer  i.nace2, robust
estimates store r7
reg withoil etsfirm hubei employment_aboveMed capital_fa_aboveMed turnover_aboveMed stateown  firmage_aboveMed bestmanage  i.day_week i.Interviewer  i.nace2, robust
estimates store r8
reg withelec etsfirm hubei employment_aboveMed capital_fa_aboveMed turnover_aboveMed stateown  firmage_aboveMed bestmanage  i.day_week i.Interviewer  i.nace2, robust
estimates store r9
esttab r* using ./TableA7.csv , replace scalars(r2 r2_a cmd) se starlevels(* .10 ** .05 *** .01) b(3) 
	
	
	
********************************************************************************
*Table A.8: Firm energy usage by ETS status
********************************************************************************

clear all
use ./ManagementChina_Panel.dta, clear
#delimit;
local energyvar "oil coal elec 
					oilOturnover coalOturnover elecOturnover";
#delimit cr 

	bysort pre2013:    eststo  : quietly estpost summarize `energyvar' if hubei==0
	bysort pre2013:    eststo  : quietly estpost summarize `energyvar' if hubei==1
	bysort pre2013:    eststo	: quietly estpost summarize `energyvar' if  hubei==0&etsfirm==1
	bysort pre2013:    eststo	: quietly estpost summarize `energyvar' if  hubei==1&etsfirm==1
	bysort pre2013:    eststo	: quietly estpost summarize `energyvar' if  hubei==0&etsfirm==0
	bysort pre2013:    eststo	: quietly estpost summarize `energyvar' if  hubei==1&etsfirm==0
	esttab using TableA8.csv, b(%9.2f) cells("mean") nonote label nodepvar replace 
estimates clear	

********************************************************************************
*Table A.9: Energy consumption by management quality and ETS
********************************************************************************

use ./ManagementChina_Panel.dta, clear	
collapse (mean) ccm_index elec  coal  oil, by(uniqid etsfirm pre2013)
reshape wide elec  coal  oil, i(uniqid etsfirm ccm_index) j(pre2013) 
foreach fff in elec coal oil  {
	gen `fff'_arcgr=(`fff'0-`fff'1)/(0.5*(`fff'0+`fff'1))
	}
	
summ ccm_index, d
gen bestmanage=1 if ccm_index>r(p50)
replace bestmanage=0 if bestmanage==.
gen etsXbestmanage=etsfirm*bestmanage

keep if elec_arcgr!=. |  coal_arcgr!=. | oil_arcgr!=. 
gen count=1
preserve 
collapse (sum) count (mean) coal1 oil1 elec1   (sd) coal_sd=coal1 oil_sd=oil1 elec_sd=elec1  , by (etsfirm bestmanage)
order etsfirm bestmanage count coal* oil* elec* 
export excel using "./TableA9_Part1", firstrow(variables) replace
restore
collapse (sum) count (mean) coal1 oil1 elec1  (sd) coal_sd=coal1 oil_sd=oil1 elec_sd=elec1 
order count coal* oil* elec* 
export excel using "./TableA9_Part2", firstrow(variables) replace


********************************************************************************
*Figure A.3: Patent Holdings Across Firms
********************************************************************************

clear all
use ./ManagementChina_CrossSection.dta, clear	

gen lipc_num = log(ipc_num)
gen lipc_green = log(ipc_greennum_nomiss )

foreach vvv in 1 50 500 1000 2000 3000 {
local logPat`vvv' = log(`vvv')
local Level_explog`vvv' = round(exp(log(`vvv')))
 }
local Level_log2 = round(exp(2))
local Level_log4 = round(exp(4))
local Level_log6 = round(exp(6))
local Level_log75 = round(exp(7.5))
local Level_log8 = round(exp(8))

twoway (hist lipc_num if ipc_num!=0 & ipc_num!=., discrete width(1)  color(black%15)) ///
	   (hist lipc_green  if ipc_num!=0 & ipc_num!=.,  discrete width(1) color(black%60)), ///
	   legend(order(1 "Any patent" 2 "Green patents"  )  position(6)) ///
	   graphregion(color(white)) bgcolor(white) xscale(range (0 6) ) ///
		xla(`logPat1'    "`Level_explog1'"     `logPat50'   "`Level_explog50'" `logPat500' "`Level_explog500'" ///
			`logPat1000' "`Level_explog1000'"   `logPat3000' "`Level_explog3000'" ) ///
	   note("Only firms reporting at least one patent (n=61)") 
	  graph export FigureA3.pdf, replace	
	
********************************************************************************
*Table B.1: Climate Change Management Index and Energy Intensity
********************************************************************************
clear
use ./ManagementChina_Panel.dta, clear	
set more off
estimates clear
*we do not have energy usage for 2007 and 2015 so drop those years
drop if year==2007 | year>=2015
foreach vvv in   lcoalOturnover loilOturnover lelecOturnover  {
eststo: xi:  reg `vvv' ccm_index exporter_nomiss exporter_miid hubei stateown lfirmage lfirmage2  lcapital_fa_nomiss lcapital_fa_miid lemployment_nomiss lemployment_miid  lcostgoods_nomiss lcostgoods_miid /// 
lmgr_tenureC_nomiss lmgr_tenureC_miid mgr_education_miid mgr_education_nomiss mgr_female ///
 lmgr_age_nomiss  lmgr_age_miid i.day_week i.Interviewer i.year i.nace2, vce(cluster uniqid)

 }
eststo: xi:  reg lturnover ccm_index exporter_nomiss exporter_miid hubei stateown lfirmage lfirmage2  lcapital_fa_nomiss lcapital_fa_miid lemployment_nomiss lemployment_miid  lcostgoods_nomiss lcostgoods_miid /// 
lmgr_tenureC_nomiss lmgr_tenureC_miid mgr_education_miid mgr_education_nomiss mgr_female ///
 lmgr_age_nomiss  lmgr_age_miid i.day_week i.Interviewer i.year i.nace2, vce(cluster uniqid)

esttab using "./TableB1.csv", replace scalars(N_clust r2 r2_a) se starlevels(* .10 ** .05 *** .01) b(3) drop(exporter_miid exporter_nomiss lemployment_miid lcapital_fa_miid lfirmage lfirmage2 lcostgoods_miid lmgr_tenureC_nomiss lmgr_tenureC_miid mgr_education_miid mgr_education_nomiss mgr_female  lmgr_age_nomiss  lmgr_age_miid _Iday_week* _IIntervi* _Inace2* _Iyear*) ///
title( "Climate Change Management and Energy Intensity" )
estimates clear
	
	
********************************************************************************
*Table B.2: Management Score Components
********************************************************************************
clear all
use ./ManagementChina_Panel.dta, clear
set more off
label var zaware_pos_CCM "Awareness"
label var zemonitor_CCM "Energy monitoring"
label var zeconstargets_score_CCM "Energy target"
label var zco2monitor_score_CCM "GHG monitoring"
label var zco2targets_score_CCM "GHG targets"
label var zenforce_score_CCM "Target enforcement"
label var zcustpress_score_CCM "Customer pressure"

# delimit ; 
local Controls1 "exporter_nomiss exporter_miid hubei stateown lfirmage lfirmage2 
				 lemployment_nomiss lemployment_miid lmgr_tenureC_nomiss lmgr_tenureC_miid 
				 mgr_education_miid mgr_education_nomiss mgr_female  lmgr_age_nomiss  lmgr_age_miid i.day_week i.Interviewer i.year i.nace2";
local Controls2 "lcapital_fa_nomiss lcapital_fa_miid
				 lcostgoods_nomiss lcostgoods_miid";
# delimit cr 

foreach ddd in zaware_pos_CCM zemonitor_CCM zeconstargets_score_CCM zco2monitor_score_CCM zco2targets_score_CCM zenforce_score_CCM zcustpress_score_CCM {
eststo: xi:  reg lturnover `ddd' `Controls1', vce(cluster uniqid)
estadd scalar Num_firm = e(N_clust)
eststo: xi:  reg lturnover `ddd' `Controls1' `Controls2', vce(cluster uniqid)
estadd scalar Num_firm = e(N_clust)
eststo: xi:  reg oilOturnover `ddd' `Controls1', vce(cluster uniqid)
estadd scalar Num_firm = e(N_clust)
eststo: xi:  reg coalOturnover `ddd' `Controls1', vce(cluster uniqid)
estadd scalar Num_firm = e(N_clust)
eststo: xi:  reg elecOturnover `ddd' `Controls1', vce(cluster uniqid)
estadd scalar Num_firm = e(N_clust)
}

esttab using TableB2.csv, replace scalars(r2 r2_a N Num_firm cmd) se starlevels(* .10 ** .05 *** .01) b(3) drop(exporter_nomiss exporter_miid hubei ///
 stateown lfirmage lfirmage2 lemployment_nomiss lemployment_miid lmgr_tenureC_nomiss lmgr_tenureC_miid mgr_education_miid mgr_education_nomiss ///
 mgr_female  lmgr_age_nomiss  lmgr_age_miid lcapital_fa_nomiss lcapital_fa_miid lcostgoods_nomiss lcostgoods_miid _Iday_week_* _IInterview_* _Iyear_* _Inace2*) ///
 title( "Table: Firm Performance and CCM Index" )  nonote label  
estimates clear


********************************************************************************
*Table B.3: New management and ETS participation
********************************************************************************
********************************************************************************
clear all
use ./ManagementChina_CrossSection.dta, clear	

foreach vvv in   employment capital_fa turnover elec coal oil coalOturnover oilOturnover elecOturnover {
	rename `vvv'_mean `vvv'
	}

foreach fff in elec coal oil coalOturnover oilOturnover elecOturnover employment  capital_fa turnover  {
	summ `fff', d
	gen `fff'_aboveMed=1 if `fff'>r(p50)
	replace `fff'_aboveMed=0 if `fff'_aboveMed==. 
	gen etsX`fff'_aboveMed=etsfirm*`fff'_aboveMed
	}

foreach fff in  mgr_tenureP firmage  {
	summ `fff', d
	gen `fff'_aboveMed=1 if `fff'>r(p50)
	replace `fff'_aboveMed=0 if `fff'_aboveMed==. 
	gen etsX`fff'_aboveMed=etsfirm*`fff'_aboveMed
	}	
gen etsXstateown=etsfirm*stateown

mmerge uniqid using "./temp/listfirmswithCoal"	
replace coal=. if _m==3
replace coal_aboveMed=. if _m==3


summ ccm_index , d
gen bestmanage=1 if ccm_index>r(p50)
replace bestmanage=0 if bestmanage==.
gen etsXbestmanage=etsfirm*bestmanage
 gen ChangeManager=0
replace ChangeManager=1 if mgr_tenureP<5
gen ChangeManagerCompany=0
replace ChangeManagerCompany=1 if mgr_tenureP<5
estimates clear 
reg ChangeManager   etsfirm i.day_week i.Interviewer  i.nace2 , robust
estimates store r1
reg ChangeManager etsfirm etsXbestmanage bestmanage  i.day_week i.Interviewer  i.nace2, robust
estimates store r2
reg ChangeManager etsfirm etsXbestmanage bestmanage employment_aboveMed capital_fa_aboveMed turnover_aboveMed stateown  firmage_aboveMed   i.day_week i.Interviewer  i.nace2, robust
estimates store r3
reg ChangeManager etsfirm etsXbestmanage bestmanage employment_aboveMed capital_fa_aboveMed turnover_aboveMed stateown  firmage_aboveMed coal_aboveMed   i.day_week i.Interviewer  i.nace2, robust
estimates store r4
esttab r* using ./TableB3.csv , replace scalars(r2 r2_a cmd) se starlevels(* .10 ** .05 *** .01) b(3) drop ( 0* 1* 2* 3* 4* 5* 6* 7* 8* 9*  )

********************************************************************************
*Table B.4: ETS Impact on Coal Use: Robustness in Subsamples
********************************************************************************
clear all
use ./ManagementChina_Panel.dta, clear
collapse (mean) ccm_index coalOturnover oilOturnover elecOturnover elec  coal  oil, by(uniqid powerS cementS ironsteelS flatglassS etsfirm beijing pre2013)
reshape wide coalOturnover oilOturnover elecOturnover elec  coal  oil, i(uniqid etsfirm beijing powerS cementS ironsteelS flatglassS) j(pre2013) 

foreach fff in coalOturnover oilOturnover elecOturnover coal oil elec {
	gen `fff'_arcgr=(`fff'0-`fff'1)/(0.5*(`fff'0+`fff'1))
	}
	
summ ccm_index , d
gen bestmanage=1 if ccm_index>r(p50)
replace bestmanage=0 if bestmanage==.
gen etsXbestmanage=etsfirm*bestmanage

estimates clear 
**1. baseline
local ii=1
foreach fff in coal  {
	reg `fff'_arcgr etsfirm bestmanage etsXbestmanage, robust 
	estimates store r`ii++'
	}

**2. exclude only power
preserve
drop if powerS==1
local ii=2
foreach fff in coal  {
	reg `fff'_arcgr etsfirm bestmanage etsXbestmanage, robust 
	estimates store r`ii++'
	}
restore

**3. exclude power and all cement
preserve
drop if powerS==1|cementS==1
local ii=3
foreach fff in coal  {
	reg `fff'_arcgr etsfirm bestmanage etsXbestmanage, robust 
	estimates store r`ii++'
	}
restore

**4. exclude power, cement, iron and steel, glass
preserve
drop if powerS==1|cementS==1|ironsteelS==1|flatglassS==1
local ii=4
foreach fff in coal {
	reg `fff'_arcgr etsfirm bestmanage etsXbestmanage, robust 
	estimates store r`ii++'
	}
restore
esttab r* using ./TableB4_SubsamLevels.csv , replace scalars(r2 r2_a cmd) se starlevels(* .10 ** .05 *** .01) b(3) ///
title( "Table B4: ETS Impact on Growth of Energy Use/Intensity_subsample" )
***********
//intensity
estimates clear 
local ii=1
**1. baseline
foreach fff in  coalOturnover   {
	reg `fff'_arcgr etsfirm bestmanage etsXbestmanage, robust 
	estimates store r`ii++'
	}
**2. exclude only power
preserve
drop if powerS==1
local ii=2
foreach fff in  coalOturnover  {
	reg `fff'_arcgr etsfirm bestmanage etsXbestmanage, robust 
	estimates store r`ii++'
	}
restore

**3. exclude power and all cement
preserve
drop if powerS==1|cementS==1
local ii=3
foreach fff in  coalOturnover  {
	reg `fff'_arcgr etsfirm bestmanage etsXbestmanage, robust 
	estimates store r`ii++'
	}
restore

**4. exclude power, cement, iron and steel, glass
preserve
drop if powerS==1|cementS==1|ironsteelS==1|flatglassS==1
local ii=4
foreach fff in  coalOturnover  {
	reg `fff'_arcgr etsfirm bestmanage etsXbestmanage, robust 
	estimates store r`ii++'
	}
restore

esttab r* using ./TableB4_SubsamInt.csv , replace scalars(r2 r2_a cmd) se starlevels(* .10 ** .05 *** .01) b(3) ///
title( "Table B4: ETS Impact on Growth of Energy Use/Intensity_subsample" )



********************************************************************************
*Table B.5: ETS Impact on Growth of Energy Use and Energy Intensity by Region
********************************************************************************
clear all
use ./ManagementChina_Panel.dta, clear
collapse (mean) ccm_index coalOturnover oilOturnover elecOturnover coal oil elec employment labor_intensity  turnover, by(firmage mgr_tenureC stateown etsfirm hubei uniqid pre2013 )

reshape wide coalOturnover oilOturnover elecOturnover coal oil elec employment labor_intensity  turnover, i(firmage mgr_tenureC stateown etsfirm hubei uniqid) j(pre2013) 

foreach fff in coalOturnover oilOturnover elecOturnover coal oil elec {
	gen `fff'_arcgr=(`fff'0-`fff'1)/(0.5*(`fff'0+`fff'1))
	}
		
summ ccm_index , d
gen bestmanage=1 if ccm_index>r(p50)
replace bestmanage=0 if bestmanage==.
gen etsXbestmanage=etsfirm*bestmanage

estimates clear 
local ii=1
foreach fff in coal oil elec coalOturnover oilOturnover elecOturnover {
	reg `fff'_arcgr etsfirm bestmanage etsXbestmanage, robust 
	estimates store r`ii++'
	reg `fff'_arcgr etsfirm bestmanage etsXbestmanage if hubei==0, robust 
	estimates store r`ii++'
	reg `fff'_arcgr etsfirm bestmanage etsXbestmanage if hubei==1, robust 
	estimates store r`ii++'
	}
esttab r* using ./TableB5.csv , replace scalars(r2 r2_a cmd) se starlevels(* .10 ** .05 *** .01) b(3) ///
title( "Table B5: ETS Impact on Growth of Energy Use and Energy Intensity (by region)" )


********************************************************************************
*Table B.6: ETS Impact on Energy Use in Sectors with an Absolute Cap
********************************************************************************
clear all
use ./ManagementChina_Panel.dta, clear
collapse (mean) ccm_index coalOturnover oilOturnover elecOturnover elec  coal  oil, by(uniqid powerS cementS etsfirm beijing pre2013)
reshape wide coalOturnover oilOturnover elecOturnover elec  coal  oil, i(uniqid etsfirm beijing powerS cementS) j(pre2013) 

foreach fff in coalOturnover oilOturnover elecOturnover coal oil elec {
	gen `fff'_arcgr=(`fff'0-`fff'1)/(0.5*(`fff'0+`fff'1))
	}
	
summ ccm_index , d
gen bestmanage=1 if ccm_index>r(p50)
replace bestmanage=0 if bestmanage==.
gen etsXbestmanage=etsfirm*bestmanage

drop if powerS==1 |( cementS==1 & beijing==0)

eststo: xi:	reg coal_arcgr etsfirm, robust 
foreach fff in coal oil elec  {
eststo: xi:	reg `fff'_arcgr etsfirm bestmanage etsXbestmanage, robust 
	}
eststo: xi:	reg coalOturnover_arcgr etsfirm, robust 
foreach fff in coalOturnover oilOturnover elecOturnover {
eststo: xi:	reg `fff'_arcgr etsfirm bestmanage etsXbestmanage, robust 
	}

esttab using TableB6.csv , replace scalars(r2 r2_a pr2 N_g cmd) se starlevels(* .10 ** .05 *** .01) b(3) ///
title( "Table : ETS Impact on Energy Use in Sectors with an Absolute Cap" )  nonote label nodepvar  
estimates clear

********************************************************************************
*Figure B.1: Trends in Coal Consumption (2008-2014): ETS vs. non-ETS
********************************************************************************
clear all
use ./ManagementChina_Panel.dta, clear
gen After2012=0 
replace After2012=1 if year>2012
gen ETSXAfter2012=After2012*etsfirm
	
summ ccm_index if etsfirm==1, d
gen bestmanage=1 if ccm_index>r(p50)
replace bestmanage=0 if bestmanage==.
gen etsXbestmanageXAfter2012=etsfirm*bestmanage*After2012

forvalues yyy=2008/2015 {
	gen Dum`yyy' =0
	replace Dum`yyy'=1 if year==`yyy'
	gen ETSX`yyy'=Dum`yyy'*etsfirm
	gen nonETSX`yyy'=Dum`yyy'*(1-etsfirm)
	gen etsXbestmanageX`yyy'=etsfirm*bestmanage*Dum`yyy'
	}
	gen notbestmanage=0
	replace notbestmanage=1 if bestmanage!=1
	forvalues yyy=2008/2015 {
	gen etsXnotbestmanageX`yyy'=etsfirm*notbestmanage*Dum`yyy'
	}

	gen etsXhubei=etsfirm*hubei
	
xtset uniqid year	
foreach fff in  coal {
		xtpoisson `fff'  ETSX2008 ///
		ETSX2009 ETSX2011 ETSX2012 ///
		ETSX2013 ETSX2014   ///
		  nonETSX2008 nonETSX2009   nonETSX2011 nonETSX2012 nonETSX2013 nonETSX2014 ///
		 ,fe vce(robust)
}
** Store coefficients as variables       
regsave, ci
drop  N

gen ETS=.
replace ETS=0 if substr(var,-9,1)=="n" 
replace ETS=1 if substr(var,-9,1)==":" 

gen year=substr(var,-4,.)

drop var
reshape wide coef ci_lower ci_upper  stderr , i(year) j(ETS) 
 insobs 1, before(3)
replace year = "2010" in 3
replace coef0 = 0 in 3
replace stderr0 = 0 in 3
replace ci_lower0 = 0 in 3
replace ci_upper0 = 0 in 3
replace coef1 = 0 in 3
replace stderr1 = 0 in 3
replace ci_lower1 = 0 in 3
replace ci_upper1 = 0 in 3
destring year, replace
gen y=0

twoway ///
            (rarea  ci_lower0 ci_upper0  year, col(black%30) fint(inten10) lwidth(0.05)) ///
            (rarea  ci_lower1 ci_upper1  year, col(black%60) fint(inten10) lwidth(0.05)) ///
            (line coef1 year , lcol(black) lwidth(medthick))  /// 
            (scatter coef1 year , col(black) msize(1)) ///
			(line coef0 year , lcol(black) lwidth(medthick) lpattern(dash))  /// 
            (scatter coef0 year , col(black) msize(1)) ///
			(line y year , lpattern(dot) lcolor(gray) lwidth(0.5)) , ///
			legend (order(4 2 6 1) label(4 "") label(2 "ETS")  label(6 "") label(1 "nonETS") ///
				label(3 "") label(5 "") label(7 "") pos(6) col(2)) ///
            graphregion(fcolor(white))  graphregion(lcolor(255 255 255))  /// 
            xline(2010.5, lpattern(dot) lcolor(black) lwidth(0.4)) xline(2012.5, lpattern(dot) lcolor(black) lwidth(0.4)) ///
			xlab(2008(1)2014) ylab(-3(1)3, labsize(medium) gstyle(dot) glwidth(0.15) )
		graph export "./FigureB1.png", as(png) replace



********************************************************************************
*Figure B.2: Trends in Energy Consumption (2008-2014): Robustness
********************************************************************************

clear all
use ./ManagementChina_Panel.dta, clear
	
summ ccm_index if etsfirm==1, d
gen bestmanage=1 if ccm_index>r(p50)
replace bestmanage=0 if bestmanage==.

forvalues yyy=2008/2015 {
	gen Dum`yyy' =0
	replace Dum`yyy'=1 if year==`yyy'
	gen etsXbestmanageX`yyy'=etsfirm*bestmanage*Dum`yyy'
	}
	gen notbestmanage=0
	replace notbestmanage=1 if bestmanage!=1
	forvalues yyy=2008/2015 {
	gen etsXnotbestmanageX`yyy'=etsfirm*notbestmanage*Dum`yyy'
	}

	gen etsXhubei=etsfirm*hubei
	
xtset uniqid year
foreach fff in coal oil elec {		 
 	preserve
	xtreg `fff'  etsXnotbestmanageX2008 ///
		etsXnotbestmanageX2009 etsXnotbestmanageX2011 etsXnotbestmanageX2012 ///
		etsXnotbestmanageX2013 etsXnotbestmanageX2014   ///
		 etsXbestmanageX2008 etsXbestmanageX2009   ///
		etsXbestmanageX2011 etsXbestmanageX2012 etsXbestmanageX2013 etsXbestmanageX2014 ///
		  Dum2008 Dum2009   Dum2011 Dum2012 Dum2013 Dum2014 hubei##year ///
		 if `fff'!=0,fe vce(robust)
	
regsave, ci
drop  N
gen bestmanage=.
replace bestmanage=0 if substr(var,-16,1)=="t" 
replace bestmanage=1 if substr(var,-16,1)=="X" 
gen year=substr(var,-4,.)
drop if bestmanage==.
drop var
reshape wide coef ci_lower ci_upper  stderr , i(year) j(bestmanage) 
 insobs 1, before(3)
replace year = "2010" in 3
replace coef0 = 0 in 3
replace stderr0 = 0 in 3
replace ci_lower0 = 0 in 3
replace ci_upper0 = 0 in 3
replace coef1 = 0 in 3
replace stderr1 = 0 in 3
replace ci_lower1 = 0 in 3
replace ci_upper1 = 0 in 3
destring year, replace
gen y=0
replace coef1=coef1/100000
replace coef0=coef0/100000
replace ci_lower0=ci_lower0/100000
replace ci_upper0=ci_upper0/100000
replace ci_lower1=ci_lower1/100000
replace ci_upper1=ci_upper1/100000
			twoway ///
            (rarea  ci_lower0 ci_upper0  year, col(black%30) fint(inten10) lwidth(0.05)) ///
            (rarea  ci_lower1 ci_upper1  year, col(black%60) fint(inten10) lwidth(0.05)) ///
            (line coef1 year , lcol(black) lwidth(medthick))  /// 
            (scatter coef1 year , col(black) msize(1)) ///
			(line coef0 year , lcol(black) lwidth(medthick) lpattern(dash))  /// 
            (scatter coef0 year , col(black) msize(1)) ///
			(line y year , lpattern(dot) lcolor(gray) lwidth(0.5)) , ///
			legend (order(4 2 6 1) label(4 "") label(2 "Above Median CCMI")  label(6 "") label(1 "Below Median CCMI") ///
				label(3 "") label(5 "") label(7 "") pos(6) col(2)) ///
            graphregion(fcolor(white))  legend(off) graphregion(lcolor(255 255 255))  /// 
            xline(2010.5, lpattern(dot) lcolor(green) lwidth(0.4)) xline(2012.5, lpattern(dot) lcolor(green) lwidth(0.4)) ///
			xlab(2008(1)2014) ylab(-4(1)2, labsize(medium) gstyle(dot) glwidth(0.15) )
			graph export ./FigureB2_`fff'.png, as(png) replace
			
restore	
}

********************************************************************************
*Table B.7: ETS Impact on Growth of Coal Use by CCMI Components: Robustness
********************************************************************************
clear all
use ./ManagementChina_Panel.dta, clear
*we only have coal use for 2008 to 2014 
drop if year==2007 |  year>=2015
collapse (mean) ccm_index zaware_pos_CCM zemonitor_CCM zeconstargets_score_CCM zco2monitor_score_CCM zco2targets_score_CCM zenforce_score_CCM zcustpress_score_CCM coalOturnover oilOturnover elecOturnover elec  coal  oil, by(uniqid  etsfirm pre2013)
reshape wide coalOturnover oilOturnover elecOturnover elec  coal  oil, i(uniqid etsfirm ) j(pre2013) 

foreach fff in coalOturnover oilOturnover elecOturnover coal oil elec {
	gen `fff'_arcgr=(`fff'0-`fff'1)/(0.5*(`fff'0+`fff'1))
	}

foreach fff in r(p50) r(p25) {
	preserve 
summ ccm_index , d
gen bestmanage=1 if ccm_index>`fff'
replace bestmanage=0 if bestmanage==.
gen etsXbestmanage=etsfirm*bestmanage

summ zaware_pos_CCM, d
gen aboveM_awareness=1 if zaware_pos_CCM>`fff'
replace aboveM_awareness=0 if aboveM_awareness==.
gen etsXaboveM_awareness=etsfirm*aboveM_awareness

summ zemonitor_CCM, d
gen aboveM_Emonitor=1 if zemonitor_CCM>`fff'
replace aboveM_Emonitor=0 if aboveM_Emonitor==.
gen etsXaboveM_Emonitor=etsfirm*aboveM_Emonitor

summ zeconstargets_score_CCM, d
gen aboveM_Etarget=1 if zeconstargets_score_CCM>`fff'
replace aboveM_Etarget=0 if aboveM_Etarget==.
gen etsXaboveM_Etarget=etsfirm*aboveM_Etarget

summ zco2monitor_score_CCM, d
gen aboveM_co2monitor=1 if zco2monitor_score_CCM>`fff'
replace aboveM_co2monitor=0 if aboveM_co2monitor==.
gen etsXaboveM_co2monitor=etsfirm*aboveM_co2monitor

summ zco2targets_score_CCM, d
gen aboveM_co2target=1 if zco2targets_score_CCM>`fff'
replace aboveM_co2target=0 if aboveM_co2target==.
gen etsXaboveM_co2target=etsfirm*aboveM_co2target

summ zenforce_score_CCM, d
gen aboveM_enforce=1 if zenforce_score_CCM>`fff'
replace aboveM_enforce=0 if aboveM_enforce==.
gen etsXaboveM_enforce=etsfirm*aboveM_enforce

summ zcustpress_score_CCM, d
gen aboveM_custpress=1 if zcustpress_score_CCM>`fff'
replace aboveM_custpress=0 if aboveM_custpress==.
gen etsXaboveM_custpress=etsfirm*aboveM_custpress

global a "aboveM_awareness etsXaboveM_awareness"
global b "aboveM_Emonitor etsXaboveM_Emonitor"
global c "aboveM_Etarget etsXaboveM_Etarget"
global d "aboveM_co2monitor etsXaboveM_co2monitor"
global e "aboveM_co2target etsXaboveM_co2target"
global f "aboveM_enforce etsXaboveM_enforce"
global g "aboveM_custpress etsXaboveM_custpress"
estimates clear 
local ii=1
foreach vvv in "$a" "$b" "$c" "$d" "$e" "$f" "$g"  {
	reg coal_arcgr etsfirm `vvv', robust
	estimates store r`ii++'
	}
esttab r* using "./TableB7_`fff'.csv" , replace scalars(r2 r2_a cmd) se starlevels(* .10 ** .05 *** .01) b(3) nonote label ///
title( "Table: ETS Impact on Growth of coal Use by CCMI Components: Robustness" )
restore
}
	
	

********************************************************************************
*Figure B.3: Historical prices and trading volumes in Beijing and Hubei
********************************************************************************
///Beijing
use ./Beijing_monthlyETStradingData.dta, replace
twoway ///
            (line price_month id if year>=2014&year<=2020 , yaxis(1) lcol(black) lwidth(medthick)) ///
            (bar volume_month id if year>=2014&year<=2020, yaxis(2) col(black%50) fint(inten30) lwidth(0.05)), ///
			legend (order(1 2) label(1 "Carbon Price") label(2 "Trading Volume")) ///
			graphregion(fcolor(white))  graphregion(lcolor(255 255 255))  /// 
			xlabel(3 "2014/1" 9 "2014/7" 15 "2015/1" 21 "2015/07" 27 "2016/1" 33 "2016/7" 39 "2017/1" 45 "2017/7" 51 "2018/1" 57 "2018/7" 63 "2019/1" 69 "2019/7" 75 "2020/1" 81 "2020/7" , angle(45) labsize(small)) ///
            xline(8, lpattern(dash) lcolor(black) lwidth(0.5)) xline(20, lpattern(dash) lcolor(black) lwidth(0.5)) ///
			xline(32, lpattern(dash) lcolor(black) lwidth(0.5)) xline(44, lpattern(dash) lcolor(black) lwidth(0.5)) ///
			xline(56, lpattern(dash) lcolor(black) lwidth(0.5)) xline(68, lpattern(dash) lcolor(black) lwidth(0.5)) xline(80, lpattern(dash) lcolor(black) lwidth(0.5))  ///
			xtitle("") ///
		    ytitle("Carbon Price (Euro/ton)",axis(1))  ///
            ytitle("Trading Volume (ton)",axis(2)) ///
			title(Beijing ETS)
			graph export FigureB3_Beijing.pdf, replace
//Hubei
use  ./Hubei_monthlyETStradingData.dta, replace

twoway ///
            (line price_month id if id>=2&year>=2014&year<=2020 , yaxis(1) lcol(black) lwidth(medthick)) ///
            (bar volume_month id if id>=2&year>=2014&year<=2020, yaxis(2) col(black%50) fint(inten30) lwidth(0.05)), ///
			legend (order(1 2) label(1 "Carbon Price") label(2 "Trading Volume")) ///
			graphregion(fcolor(white))  graphregion(lcolor(255 255 255))  /// 
			xlabel(3 "2014/6" 9 "2014/12" 15 "2015/6" 21 "2015/12" 27 "2016/6" 33 "2016/12" 39 "2017/6" 45 "2017/12" 51 "2018/6" 57 "2018/12" 63 "2019/6" 69 "2019/12" 75 "2020/7" 80 "2020/12" , angle(45) labsize(small)) ///
            xline(16, lpattern(dash) lcolor(black) lwidth(0.5)) xline(28, lpattern(dash) lcolor(black) lwidth(0.5)) ///
			xline(40, lpattern(dash) lcolor(black) lwidth(0.5)) xline(52, lpattern(dash) lcolor(black) lwidth(0.5)) ///
			xline(64, lpattern(dash) lcolor(black) lwidth(0.5)) xline(75, lpattern(dash) lcolor(black) lwidth(0.5)) ///
			xtitle("") ///
		    ytitle("Carbon Price (Euro/ton)",axis(1))  ///
            ytitle("Trading Volume (ton)",axis(2)) ///
			title(Hubei ETS)
			graph export FigureB3_Hubei.pdf, replace
	
	